package com.zsrt.spring.boot.user.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zsrt.spring.boot.user.entity.UserEntity;
import com.zsrt.spring.boot.user.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService service;
	
	
	/**
	 * http://localhost:8088/user/log?phone=13926583118&password=123456
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/log")
	public Map<String,String> login(UserEntity user){
		
		Map<String,String> map = new HashMap<String,String>();
		
		int counter =service.login(user);
		
		if(counter ==1){
			map.put("code", "200");
			map.put("message", "success");
		}else{
			map.put("code", "500");
			map.put("message", "failure");
		}
		
		return map;
	}
	
	/**
	 * http://localhost:8088/user/register?phone=13926583111&password=123456
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/register")
	public Map<String,String> register(UserEntity user){
		
		Map<String,String> map = new HashMap<String,String>();
		
		int counter =service.register(user);
		
		if(counter ==1){
			map.put("message", "success");
		}else{
			map.put("message", "failure");
		}
		
		return map;
	}

}
